package MEET.src.code;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;

    public class MeetingController {
        private MeetingService meetingService = new MeetingServiceImpl();
        private MeetingDao1 meetingDao;
        private MeetingDao1 MeetingDao;

        public List<Meeting> searchMeetings(String meetingId,String hostName) {
            return meetingService.searchMeetings(meetingId,hostName);
        }

        public Meeting getMeetingDetails(String meetingId) {
            return meetingService.getMeetingDetails(meetingId);
        }


        public String joinMeeting(String meetingId, String userId) {
            // 直接返回成功，不做任何处理
            return "参加成功";
        }

        public List<Meeting> getHostedMeetings(String userId) {
            return meetingService.getHostedMeetings(userId);
        }

        public MeetingController() {
            this.meetingService = new MeetingServiceImpl();
        }

        public List<Meeting> searchHistoryMeetings(String searchKey, Timestamp startDate, Timestamp endDate) {
            // 添加null检查
            if (startDate == null && endDate == null) {
                // 默认查询最近3个月数据
                Calendar calendar = Calendar.getInstance();
                endDate = (Timestamp) calendar.getTime();
                calendar.add(Calendar.MONTH, -3);
                startDate = (Timestamp) calendar.getTime();
            }
            return meetingService.searchHistoryMeetings(searchKey, startDate, endDate);
        }
    }

